package defpackage; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.nio.channels.FileChannel; import java.util.ArrayList; import java.util.Enumeration; import java.util.Iterator; import java.util.Map; import java.util.zip.ZipEntry; import java.util.zip.ZipError; import java.util.zip.ZipFile; import java.util.zip.ZipInputStream; /* renamed from: abac reason: default package */ public final class abac extends aazr { private static final String TAG = null; public final abbe CCG; public abac() { super(CBs); this.CCG = null; } abac(InputStream inputStream, aazs aazs) throws IOException { super(aazs); this.CCG = new abbh(new ZipInputStream(inputStream)); } abac(String str, aazs aazs) { super(aazs); ZipFile air = abao.air(str); if (air == null) { throw new ZipError("Can't open the specified file: '" + str + "'"); } this.CCG = new abbf(air); } private aazv a(ZipEntry zipEntry) { try { if (aic(zipEntry.getName())) { return null; } return aazz.aib(abao.aio(zipEntry.getName())); } catch (Exception e) { hm.e(TAG, "Entry " + zipEntry.getName() + " is not valid, so this part won't be add to the package.", e); return null; } } private static boolean aic(String str) { return str.length() == 19 && str.charAt(0) == '[' && (str.charAt(1) | ' ') == 99 && (str.charAt(2) | ' ') == 111 && (str.charAt(3) | ' ') == 110 && (str.charAt(4) | ' ') == 116 && (str.charAt(5) | ' ') == 101 && (str.charAt(6) | ' ') == 110 && (str.charAt(7) | ' ') == 116 && str.charAt(8) == '_' && (str.charAt(9) | ' ') == 116 && (str.charAt(10) | ' ') == 121 && (str.charAt(11) | ' ') == 112 && (str.charAt(12) | ' ') == 101 && (str.charAt(13) | ' ') == 115 && str.charAt(14) == ']' && str.charAt(15) == '.' && (str.charAt(16) | ' ') == 120 && (str.charAt(17) | ' ') == 109 && (str.charAt(18) | ' ') == 108; } /* access modifiers changed from: protected */ @Override // defpackage.aazp public final aazt b(aazv aazv, String str, boolean z) { if (str == null) { throw new IllegalArgumentException("contentType"); } else if (aazv == null) { throw new IllegalArgumentException("partName"); } else { try { return new abaj(this, aazv, str, z); } catch (aazi e) { hm.e(TAG, "InvalidFormatException", e); return null; } } } /* access modifiers changed from: protected */ @Override // defpackage.aazp public final void d(aazv aazv) { if (aazv == null) { throw new IllegalArgumentException("partUri"); } } /* access modifiers changed from: protected */ @Override // defpackage.aazp public final aazt e(aazv aazv) { return (aazt) this.CBu.get(aazv); } /* access modifiers changed from: protected */ @Override // defpackage.aazp public final void hdg() throws IOException { hcY(); if (this.CBF != null && !"".equals(this.CBF)) { File file = new File(this.CBF); if (!file.exists()) { file.createNewFile(); } try { ew.assertNotNull("tmpPackageFile should not be null! ", this.CBG); bH(this.CBG); if (!this.CBG.renameTo(file)) { FileChannel channel = new FileInputStream(this.CBG).getChannel(); FileChannel channel2 = new FileOutputStream(file).getChannel(); channel.transferTo(0, channel.size(), channel2); channel.close(); channel2.close(); } } finally { if (this.CBG.exists() && !this.CBG.delete()) { hm.d(TAG, "The temporary file: '" + file.getAbsolutePath() + "' cannot be deleted ! Make sure that no other application use it."); } this.CBG = null; } } } /* access modifiers changed from: protected */ @Override // defpackage.aazp public final void hdh() { try { if (this.CCG != null) { this.CCG.close(); } } catch (IOException e) { hm.e(TAG, "IOException", e); } } /* access modifiers changed from: protected */ @Override // defpackage.aazp public final aazt[] hdi() throws aazi { if (this.CBu == null) { this.CBu = new aazu(); } if (this.CCG == null) { return (aazt[]) this.CBu.values().toArray(new aazt[this.CBu.values().size()]); } ArrayList arrayList = new ArrayList(this.CCG.size()); Enumeration<? extends ZipEntry> hef = this.CCG.hef(); boolean z = false; while (hef.hasMoreElements()) { ZipEntry zipEntry = (ZipEntry) hef.nextElement(); if (z || !aic(zipEntry.getName())) { arrayList.add(zipEntry); } else { try { this.CBE = new aban(this.CCG.getInputStream(zipEntry), this); z = true; } catch (IOException e) { throw new aazi(e.getMessage()); } } } int size = arrayList.size(); aazv[] aazvArr = new aazv[size]; String[] strArr = new String[size]; for (int i = 0; i < size; i++) { ZipEntry zipEntry2 = (ZipEntry) arrayList.get(i); aazv a = a(zipEntry2); if (a != null) { String h = this.CBE != null ? this.CBE.h(a) : null; if (h != null) { if (h.equals("application/vnd.openxmlformats-package.relationships+xml")) { try { this.CBu.put(a, new abad(this, zipEntry2, a, h)); } catch (aazj e2) { throw new aazi(e2.getMessage()); } } else { strArr[i] = h; aazvArr[i] = a; } } } } for (int i2 = 0; i2 < size; i2++) { String str = strArr[i2]; if (str != null) { aazv aazv = aazvArr[i2]; try { this.CBu.put(aazv, new abad(this, (ZipEntry) arrayList.get(i2), aazv, str)); } catch (aazj e3) { throw new aazi(e3.getMessage()); } } } return (aazt[]) this.CBu.values().toArray(new abad[this.CBu.size()]); } @Override // defpackage.aazp public final void j(OutputStream outputStream) { hcY(); try { vpv vpv = !(outputStream instanceof vpv) ? new vpv(outputStream) : (vpv) outputStream; if (ahK("http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties").size() == 0) { new abav().a(this.CBA, vpv); this.CBw.a(this.CBA.hdn().CBX, abab.INTERNAL, "http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties", null); if (!this.CBE.aid("application/vnd.openxmlformats-package.core-properties+xml")) { this.CBE.b(this.CBA.hdn(), "application/vnd.openxmlformats-package.core-properties+xml"); } } if (this.CBB != null && ahK("http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties").size() == 0) { new abau().a(this.CBB, vpv); this.CBw.a(this.CBB.hdn().CBX, abab.INTERNAL, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties", null); if (!this.CBE.aid("application/vnd.openxmlformats-officedocument.extended-properties+xml")) { this.CBE.b(this.CBB.hdn(), "application/vnd.openxmlformats-officedocument.extended-properties+xml"); } } if (this.CBC != null && ahK("http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties").size() == 0) { new abat().a(this.CBC, vpv); this.CBw.a(this.CBC.hdn().CBX, abab.INTERNAL, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/custom-properties", null); if (!this.CBE.aid("application/vnd.openxmlformats-officedocument.custom-properties+xml")) { this.CBE.b(this.CBC.hdn(), "application/vnd.openxmlformats-officedocument.custom-properties+xml"); } } abaw.a(hde(), aazz.CCu, vpv); abaf abaf = this.CBE; aoz aoz = new aoz(); ang d = aoz.d("http://schemas.openxmlformats.org/package/2006/content-types", "", "Types"); for (Map.Entry<String, String> entry : abaf.CCJ.entrySet()) { d.cp("Default").m("Extension", entry.getKey()).m("ContentType", entry.getValue()); } if (abaf.CCK != null) { for (Map.Entry<aazv, String> entry2 : abaf.CCK.entrySet()) { d.cp("Override").m("PartName", entry2.getKey().getName()).m("ContentType", entry2.getValue()); } } aoz.normalize(); abaf.b(aoz, vpv); d.Ir(); Iterator<aazt> it = hdd().iterator(); while (it.hasNext()) { aazt next = it.next(); if (!next.CBT) { abal abal = (abal) this.CBx.get(next.CBS); if (abal != null) { if (!abal.a(next, vpv)) { throw new aazk("The part " + next.hdn().CBX + " fail to be saved in the stream with marshaller " + abal); } } else if (!this.CBy.a(next, vpv)) { throw new aazk("The part " + next.hdn().CBX + " fail to be saved in the stream with marshaller " + this.CBy); } } } vpv.close(); } catch (Exception e) { throw new RuntimeException(e.getMessage()); } } }